package com.mall.server.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mall.commons.exceotion.BusinessException;
import com.mall.commons.exceotion.ErrorResult;
import com.mall.commons.utils.PageUtils;
import com.mall.dubbo.api.ReturnApplyApi;
import com.tanhua.model.dto.OmsOrderReturnApplyDto;
import com.tanhua.model.dto.OmsOrderReturnApplyUpdateDto;
import com.tanhua.model.dto.ReturnApplyDto;
import com.tanhua.model.vo.PageVo;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

@Service
public class ReturnApplyService {

    @DubboReference
    private ReturnApplyApi returnApplyApi;

    //分页查询退货申请
    public PageVo listOmsOrderReturnApply(ReturnApplyDto returnApplyDto) {
        Page page = returnApplyApi.listOmsOrderReturnApply(returnApplyDto);

        if (page == null) {
            throw new BusinessException(ErrorResult.emptyError());
        }
        PageVo pageDto = PageUtils.getPageVo(page);

        return pageDto;
    }

    //获取退货申请详情
    public OmsOrderReturnApplyDto getById(Integer id) {
        OmsOrderReturnApplyDto oos = returnApplyApi.getById(id);
        if (oos == null) {
            throw new BusinessException(ErrorResult.emptyError());
        }
        return oos;
    }

    //修改退货申请状态
    public void updates(Integer id, OmsOrderReturnApplyUpdateDto dto) {
        boolean extis = returnApplyApi.updates(id, dto);
        if (!extis) {
            throw new BusinessException(ErrorResult.emptyError());
        }
    }

    //批量删除退货申请
    public void deletes(Integer[] ids) {
        boolean extis = returnApplyApi.deletes(ids);
        if (!extis) {
            throw new BusinessException(ErrorResult.emptyError());
        }
    }
}
